<template>
	</div>
	<el-table :data="workList" border style="margin: 20px;">
		<el-table-column align="center" prop="id" label="编号"></el-table-column>
		<el-table-column prop="endTime" label="结束时间"></el-table-column>
		<el-table-column prop="workTitle" label="作业标题"></el-table-column>
		<el-table-column label="下载">
			<template slot-scope="scope">
				<el-link style="margin-left: 20px;" :href="`http://localhost:9090/student/downFile/`+scope.row.workId" target="_blank">下载作业</el-link>
			</template>
		</el-table-column>
		<el-table-column label="操作">
			
			<template slot-scope="scope">
				<span v-if="pdStatus(scope.row)==0">作业已完成</span>
				<el-upload
				style="display: inline"
				v-else-if="pdStatus(scope.row)==1"
				  class="upload-demo"
				  ref="upload"
				  :on-success="success"
				  :action="`http://localhost:9090/work/uploadStudentFile/`+user.id+`/`+scope.row.workId"
				  :on-preview="handlePreview"
				  :on-remove="handleRemove"
				  :file-list="fileList"
					>
				  <el-button slot="trigger" size="small" type="primary">提交作业</el-button>
				</el-upload>
				<span v-else>作业提交已经结束</span>				
			</template>
		</el-table-column>
	</el-table>
</template>

<script>
import { log } from 'video.js'
	export default {
		data(){
			return{
				ctId:0,
				workList:[],
				user:{}
			}
		},
		methods:{
			success(resp){
				if(resp.code==200){
					this.getWorkList(this.ctId);
				}
			},
			getWorkList(ctid){
				//发送请求
				let user = JSON.parse(localStorage.getItem("user"))
					this.user = user
				this.request.get("/work/getStudentWork/"+ctid+"/"+user.id).then(res=>{
					this.workList = res.data
				})
			},
			pdStatus(row){
				console.log(row)
				if(row.isFinish==1){
					//作业已完成
					return 0
				}else if(row.isFinish==0){
					//作业未提交
					//判断是否已经到了提交截止日期
					console.log(new Date(row.endTime))
					console.log(new Date())
					if(new Date(row.endTime) > new Date()){
						//未到时间
						return 1
					}else{
						return 2
					}
				}
			},
			downFile(fileUrl){
				this.request.post("/student/downFile",fileUrl).then(resp=>{
					
				})
			}
		},
		created() {
			// 获取路由传来的参数
			this.ctId = this.$route.query.ctId
			this.getWorkList(this.ctId)
		},
		
	}
</script>

<style>
</style>